package com.threadpool;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ScheduledThreadPoolRunner {

    private static final Logger logger = LoggerFactory.getLogger(ScheduledThreadPoolRunner.class);

    public static void main(String[] args) {
        ScheduledThreadPoolExecutor scheduledThreadPool = new ScheduledThreadPoolExecutor(10);
        scheduledThreadPool.schedule(() ->{
            logger.info("我要延迟5s");
            try {
                Thread.currentThread().sleep(10000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },5000, TimeUnit.MILLISECONDS);
        scheduledThreadPool.schedule(() ->{
            logger.info("我要延迟10s");
            try {
                Thread.currentThread().sleep(10000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },10000,TimeUnit.MILLISECONDS);
        scheduledThreadPool.schedule(() ->{
            logger.info("我要延迟3s");
            try {
                Thread.currentThread().sleep(10000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },3000,TimeUnit.MILLISECONDS);
        scheduledThreadPool.schedule(() ->{
            logger.info("我要延迟1s");
            try {
                Thread.currentThread().sleep(10000L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },1000,TimeUnit.MILLISECONDS);
    }

}